﻿//using UnityEngine;
//using UnityEngine.UI;
//using UnityEngine.Events;

//namespace QQSDK
//{
//    [RequireComponent(typeof(Button))]
//    public class PurchaseButton : MonoBehaviour
//    {
//        public ProductType productType;
//        public string productIdentifier;
//        public Text descriptionText;//商描述
//        public Text priceText;//价格信息
//        public Text titileText;//标题
//        public static UnityAction<string, ProductType> onRestoreSucceed;

//        public static UnityAction<KKPurchase.PurchaseState,string> onPurchaseCallback;

//        // Use this for initialization
//        void Start() {
//            KKPurchase.instance.onFetchProductionDetailComplete += RefreshInfo;
//            if (productType == ProductType.NonConsume||productType==ProductType.Subs)
//            {
//                KKPurchase.instance.onRestore += OnRestore;
//            }
//        }
//        public void OnRestore(string productIdentifier)
//        {
//            if (this.productIdentifier.Equals(productIdentifier))
//            {
//                SDKFunc.LogError("恢复购买" + productIdentifier);
//                onRestoreSucceed?.Invoke(productIdentifier, productType);
//            }
//        }
//        void RefreshInfo(KKPurchase.PurchaseState fetchResult,ProductType type)
//        {
//            switch (fetchResult)
//            {
//                case KKPurchase.PurchaseState.FetchSucceed:
//                    if (this.productType == type)
//                    {
//                        ProductDetail productDetail = KKPurchase.instance.QueryProductInfo(productIdentifier);
//                        if (productDetail != null)
//                        {
//                            if (descriptionText != null)
//                                descriptionText.text = productDetail.localizedDescription;
//                            if (priceText != null)
//                                priceText.text = productDetail.price;
//                            if (titileText != null)
//                                titileText.text = productDetail.localizedTitle;
//                        }
//                        else
//                        {
//                            SDKFunc.LogError("为查询到该信息");
//                        }
//                    }
//                    break;
//            }
//        }
//        public void OnClick()
//        {
//            if(!string.IsNullOrEmpty(productIdentifier))
//            KKPurchase.instance.BuyProduct(new ProductDetail(productIdentifier, ProductType.Consume));
//        }
//        public void OnDestroy()
//        {
//            KKPurchase.instance.onFetchProductionDetailComplete -= RefreshInfo;
//        }
//    }
//}

